package org.example.aaaatest.a1;

import com.amap.car.order.i18n.util.TimeZoneUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.TimeZone;

/**
 * @description:
 * @author: wangbaogui
 * @create: 2025/2/21 15:49
 **/
public class aaa {
    public static void main(String[] args) {
        // 假设 originalDate 是东八区的时间
        Date originalDate = new Date();

        TimeZone timeZone = TimeZoneUtil.getAdminTimeZone(39.762315,35.713246);


        // 目标时区是东九区
        ZoneId targetZone = timeZone.toZoneId();

        // 将 Date 转换为 Instant
        ZonedDateTime originalZonedDateTime = originalDate.toInstant().atZone(ZoneId.of("GMT+8"));

        // 转换为目标时区的 ZonedDateTime
        ZonedDateTime targetZonedDateTime = originalZonedDateTime.withZoneSameInstant(targetZone);

        // 将目标时区的 ZonedDateTime 转换回 Date
        Date targetDate = Date.from(targetZonedDateTime.toInstant());

        // 存储或使用 targetDate
        System.out.println("转换后的时间: " + targetDate);

        ZoneId originalZone = ZoneId.of("Asia/Shanghai"); // 明确原时区为东八区
        ZonedDateTime originalZdt = originalDate.toInstant().atZone(originalZone);
        ZonedDateTime targetZdt = originalZdt.withZoneSameInstant(targetZone); // 转换时区
        Date convertedDate = Date.from(targetZdt.toInstant()); // 存储为Date类型
        System.out.println("convertedDate = " + convertedDate);
    }







    public void aa() {

        boolean s = StringUtils.isBlank("s");
        // 假设jsonResponse是包含上述JSON的字符串
        String j = "{\n" +
                "    \"resultCode\": \"SUCCESS\",\n" +
                "    \"data\": {\n" +
                "        \"hitchSnapShot\": {\n" +
                "            \"carListTraceId\": \"s000fa624016cf824281aebddcf50153b1dc\",\n" +
                "            \"communalInfoDto\": {\n" +
                "                \"adiu\": \"n767311b6f1197def8eieaabb99aee\",\n" +
                "                \"bizVersion\": \"080005\"\n" +
                "            },\n" +
                "            \"transportInfoDtoList\": [\n" +
                "                {\n" +
                "                    \"amapRideType\": \"gd_hitch\",\n" +
                "                    \"brandIconUrl\": \"https://gw.alicdn.com/imgextra/i1/O1CN01ilpAQq1fujmBIAMou_!!6000000004067-2-tps-132-132.png\",\n" +
                "                    \"brandName\": \"拼座\",\n" +
                "                    \"brandSimpleName\": \"拼座\",\n" +
                "                    \"businessModel\": 7,\n" +
                "                    \"gdEstimatePrice\": 3661\n" +
                "                },\n" +
                "                {\n" +
                "                    \"amapRideType\": \"gd_hitch\",\n" +
                "                    \"brandIconUrl\": \"https://gw.alicdn.com/imgextra/i2/O1CN01i18bBq1BySVjNtCn0_!!6000000000014-2-tps-132-132.png\",\n" +
                "                    \"brandName\": \"独享\",\n" +
                "                    \"brandSimpleName\": \"独享\",\n" +
                "                    \"businessModel\": 7,\n" +
                "                    \"gdEstimatePrice\": 4779\n" +
                "                }\n" +
                "            ],\n" +
                "            \"transportStoreScene\": 1000\n" +
                "        }\n" +
                "    }\n" +
                "}";


        // 创建ObjectMapper实例
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            // 解析JSON字符串为JsonNode对象
            JsonNode rootNode = objectMapper.readTree(j);
            //  System.out.println(rootNode.toPrettyString());

            // 获取data节点
            JsonNode dataNode = rootNode.path("data");
            // System.out.println("dataNode = " + dataNode);

            // 获取transportInfoDtoList数组
            JsonNode hitchSnapShot = dataNode.path("hitchSnapShot");
            System.out.println("hitchSnapShot = " + hitchSnapShot);

            JsonNode transportInfoDtoList1 = hitchSnapShot.path("`transportInfoDtoList`");

            // JsonNode transportInfoDtoList = rootNode.at("/data/hitchSnapShot/transportInfoDtoList");

            // 遍历transportInfoDtoList数组寻找拼座价格
            for (JsonNode transportNode : transportInfoDtoList1) {
                String brandName = transportNode.path("brandName").asText();
                System.out.println("当前品牌名称: " + brandName);
                if ("拼座".equals(brandName)) {
                    String price = transportNode.path("gdEstimatePrice").asText();
                    System.out.println("拼座价格: " + price);
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void parseJson() {
        // 假设jsonResponse是包含上述JSON的字符串
        String jsonResponse = "{\n" +
                "    \"resultCode\": \"SUCCESS\",\n" +
                "    \"data\": {\n" +
                "        \"hitchSnapShot\": {\n" +
                "            \"carListTraceId\": \"s000fa624016cf824281aebddcf50153b1dc\",\n" +
                "            \"communalInfoDto\": {\n" +
                "                \"adiu\": \"n767311b6f1197def8eieaabb99aee\",\n" +
                "                \"bizVersion\": \"080005\"\n" +
                "            },\n" +
                "            \"transportInfoDtoList\": [\n" +
                "                {\n" +
                "                    \"amapRideType\": \"gd_hitch\",\n" +
                "                    \"brandIconUrl\": \"https://gw.alicdn.com/imgextra/i1/O1CN01ilpAQq1fujmBIAMou_!!6000000004067-2-tps-132-132.png\",\n" +
                "                    \"brandName\": \"拼座\",\n" +
                "                    \"brandSimpleName\": \"拼座\",\n" +
                "                    \"businessModel\": 7,\n" +
                "                    \"gdEstimatePrice\": 3661.2\n" +
                "                },\n" +
                "                {\n" +
                "                    \"amapRideType\": \"gd_hitch\",\n" +
                "                    \"brandIconUrl\": \"https://gw.alicdn.com/imgextra/i2/O1CN01i18bBq1BySVjNtCn0_!!6000000000014-2-tps-132-132.png\",\n" +
                "                    \"brandName\": \"独享\",\n" +
                "                    \"brandSimpleName\": \"独享\",\n" +
                "                    \"businessModel\": 7,\n" +
                "                    \"gdEstimatePrice\": 4779\n" +
                "                }\n" +
                "            ],\n" +
                "            \"transportStoreScene\": 1000\n" +
                "        }\n" +
                "    }\n" +
                "}";

        // 创建ObjectMapper实例
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            // 解析JSON字符串为JsonNode对象
            JsonNode rootNode = objectMapper.readTree(jsonResponse);

            // 使用at方法直接访问深层嵌套节点
            JsonNode transportInfoDtoList = rootNode.at("/data/hitchSnapShot/transportInfoDtoList");

            // 遍历transportInfoDtoList数组寻找拼座价格
            for (JsonNode transportNode : transportInfoDtoList) {
                String brandName = transportNode.path("brandName").asText();
                if ("拼座".equals(brandName)) {
                    long price = transportNode.path("gdEstimatePrice").asLong(); // 使用asInt()获取整数
                    System.out.println("拼座价格: " + price);
                    break;
                }
            }
        } catch (Exception e) {
            // 使用日志记录异常，而不是printStackTrace
            System.err.println("解析JSON时发生错误: " + e.getMessage());
        }
    }

   /* public void bb() {
        String departTime = CalendarUtil.toString(rq.getNumber().getDepartTime(),CalendarUtil.TIME_PATTERN); // yyyy-mm-dd hh:mm:ss
        if (agentNumber != null
                && ShiftTypeEnum.FLOAT_SCHEDULE != ShiftTypeEnum.of(rq.getNumber().getShiftType())
                && StringUtils.isNotEmpty(departTime)
                && !departTime.equals(agentNumber.getStartDate() + " " + agentNumber.getStartTime() + ":00")) {
            rs = ResultUtils.failResultDO("", "下单时出发时间发生变化");
            return rs;
        }
        创建订单的某一段代码，以前的代码逻辑里面getShiftType()是private String shiftType;类型，可以直接调用第一段代码
        现在的getShiftType()是private Integer shiftType;类型，需求是不能改动字段的类型，怎么使得第二段代码里面包含第一段代码的value != null ? value.trim() : “”这个



                以下是
        ShiftTypeEnum枚举类里的代码

        FIXED_SCHEDULE(0, "固定班"), //default
                FLOAT_SCHEDULE(1, "流水班"),
                TEMP_SCHEDULE(2, "加班车");

        //第一段
        public final static ShiftTypeEnum of(String value) {
            try {
                int v = Integer.parseInt(value != null ? value.trim() : "");
                return of(v);
            } catch (Exception e) {
                return ShiftTypeEnum.FIXED_SCHEDULE;
            }


        }

      //  第二段
        public final static ShiftTypeEnum of(int value) {
            for (ShiftTypeEnum e : ShiftTypeEnum.values()) {
                if (e.getValue() == value) {
                    return e;
                }
            }
            return ShiftTypeEnum.FIXED_SCHEDULE;
        }
    }*/

}
